package ore.example.pokemonPb.commond;

import ore.example.pokemonPb.GUI.PokedexGUI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PokePb implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
        if (!(commandSender instanceof Player)) {
            commandSender.sendMessage("§c只有玩家才能使用这个命令!");
            return true;
        }

        Player player = (Player) commandSender;

        // 如果没有提供参数（即只输入了 /宝可梦图鉴）
        if (strings.length == 0) {
            player.sendMessage("§c请指定要查看的宝可梦世代！");
            player.sendMessage("§e可用命令：");
            player.sendMessage("§6/图鉴1 §7- 查看第一世代宝可梦");
            player.sendMessage("§6/图鉴2 §7- 查看第二世代宝可梦");
            // ... 依次列出所有世代
            player.sendMessage("§6/图鉴9 §7- 查看第九世代宝可梦");
            player.sendMessage("§a或者使用 §e/宝可梦图鉴 <1-9> §a来指定世代");
            return true; // 返回true表示命令语法正确，只是提示用户正确用法
        }

        // 处理参数：/pokedex <世代数>
        int generation;
        try {
            generation = Integer.parseInt(strings[0]);
            if (generation < 1 || generation > 9) {
                player.sendMessage("§c世代参数必须在 1-9 之间！");
                return true;
            }
        } catch (NumberFormatException e) {
            player.sendMessage("§c请输入有效的世代数字（1-9）！");
            player.sendMessage("§e用法: /宝可梦图鉴 <1-9>");
            return true;
        }

        // 打开指定世代的宝可梦图鉴GUI
        try {
            PokedexGUI.openPokedex(player, generation);
            player.sendMessage("§a已打开第 " + generation + " 世代宝可梦图鉴!");
        } catch (Exception e) {
            player.sendMessage("§c打开图鉴时出现错误: " + e.getMessage());
            e.printStackTrace();
        }

        return true;
    }
}